<?php

class users{
	public $account;
	public $code;	
	/*public $mysql_server_name,$mysql_username,$mysql_password,$mysql_database,$conn;*/
	public $check_code,$check_arr;
	public $code_len,$code_arr;
    public $code_str,$check_str;

    //构造函数

//获取用户名和密码
function getacc(){
	@$this->account = $_POST['name'];
	return $this->account;
}

//获取用户密码
function getcode(){
    @$this->code = $_POST['code'];
    return $this->code;
}

//显示用户信息
function show(){
    echo $this->account."您好"."<br>"."<br>";
	}

//访问数据库
function connected(){
   $mysql_server_name='localhost'; 

   $mysql_username='root'; 
 
   $mysql_password=''; 
 
   $mysql_database='users';

   $conn=mysqli_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database='users');

   $this->check_code = mysqli_query($conn,"SELECT code FROM user WHERE account='$this->account'");
   $this->check_arr = mysqli_fetch_array($this->check_code);
   $this->check_str = $this->check_arr['code'];

}

//将用户密码反序
function change(){
	$this->code_len=strlen($this->code);
	$this->code_arr=str_split($this->code);
	for($i=0;$i<(($this->code_len)/2);$i++)
	{
       $t=$this->code_arr[$i];
       $this->code_arr[$i]=$this->code_arr[$this->code_len-1-$i];
       $this->code_arr[$this->code_len-1-$i]=$t;   	
	}
	$this->code_str = implode("", $this->code_arr);

}

//检验密码是否正确并跳转
function exam(){
	/*echo $this->code_str;
	echo $this->check_str;*/
    if($this->code_str==$this->check_str)
    {
    	echo '欢迎'.$this->account."<br>"."<br>".'点击 <a href="logged.php"> 进入'."<br>"."<br>";  
    }
    else{
    	exit('登录失败，<a href="log.php">返回</a>');
    }

}


}
//调用函数
$user = new users();
$user -> getacc();
$user -> getcode();
$user -> show();
$user -> connected();
$user -> change();
$user -> exam();

?>